package com.hongye.customer.controller;

import com.hongye.common.entity.CustomerEntity;
import com.hongye.common.entity.PublishEntity;
import com.hongye.common.response.ResponseResult;
import com.hongye.common.utils.MyFileload;
import com.hongye.customer.service.CustomerService;
import com.hongye.customer.web.PayWebController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.HashMap;

@RestController
@RequestMapping("/customer")
public class CustomerController {

    @Autowired
    private CustomerService customerService;

    @Autowired
    private PayWebController payWebController;

    //轮播图查询
    @RequestMapping("/slideShow")
    public ResponseResult slideShowEntityList() {
        return customerService.slideList();
    }

    //买房
    @RequestMapping("/buyHouse")
    public ResponseResult buyHouse(@RequestParam("isNewHouse") int isNewHouse) {
        return customerService.buyHouse(isNewHouse);
    }

    //租房
    @RequestMapping("/rentHouse")
    public ResponseResult rentHouse() {
        return customerService.rentHouse();
    }

    //求租,求购
    @RequestMapping("/demandHouse")
    public ResponseResult demandHouse(@RequestParam("publish_type_id") int publish_type_id,
                                            @RequestParam("house_type_id") int house_type_id,
                                            @RequestParam("city_id") int city_id) {
        return customerService.demandHouse(publish_type_id, house_type_id, city_id);

    }

    //发布信息接口
    @RequestMapping("/buyHouseInsert")
    public ResponseResult buyHouseInsert(@RequestBody PublishEntity publishEntity) {
        String orderId = customerService.buyHouseInsert(publishEntity);
        try {
            payWebController.payOrder(orderId);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return new ResponseResult(401,"发布成功");
    }

    //资讯
    @RequestMapping("/information")
    public ResponseResult information() {
        return customerService.informationList();
    }

    //楼市圈
    @RequestMapping("/houseRing")
    public ResponseResult houseRing() {
        return customerService.houseRing();
    }

    //经纪人
    @RequestMapping("/broker")
    public ResponseResult brokerList() {
        return customerService.brokerList();
    }

    //团购看房
    @RequestMapping("/groupPurchase")
    public ResponseResult groupPurchase() {
        return customerService.groupPurchase();
    }

    //我要报名
    @RequestMapping("/apply")
    public ResponseResult apply(Integer customerId,Integer groupId){
        return customerService.apply(customerId,groupId);
    }
    //首页
    @RequestMapping("/homePage")
    public ResponseResult homePage() {
        return customerService.homePage();
    }

    //根据id查询
    @RequestMapping("/findById")
    public CustomerEntity findById(@RequestParam("id") int id) {
        CustomerEntity customerEntity = customerService.findById(id);
        return customerEntity;
    }

    //文件上传
    @RequestMapping("/fileUpload")
    public ResponseResult fileUpload(MultipartFile file){
        String upload = MyFileload.upload(file);
        HashMap<String, Object> map = new HashMap<>();
        map.put("upload",upload);
        return new ResponseResult(402,"上传成功",map);
    }
}
